home *** CD-ROM | disk | FTP | other *** search
- /* MyFolders.c
- * Deal with finding and creating folders
- * ©1992 Working Software, Inc.
- * This source code is copyrighted. Permission is granted to use the Word Services
- * portion of the Writeswell Jr. source code in your own programs, but you
- * may not distribute the Writeswell Jr. word-processor code as a
- * commercial product. If you modify the code, please do not call it
- * Writeswell Jr. (or Writeswell.) This will ensure that people understand the
- * program and don’t have to deal with a number of different versions with
- * who-knows-what going on in the code.
- *
- * Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
- * 17 Feb 91 Mike Crawford
- */
- #include "MyFolders.h"
-
- OSErr GetSysVolID( short *sysVolRefNumPtr, long *blessedIDPtr )
- {
- WDPBRec wPB;
- SysEnvRec envRec;
- OSErr result;
- Str31 name;
-
- if ( result = SysEnvirons( curSysEnvVers, &envRec ) ){
- return result;
- }
-
- /*
- ClearBlock( (char*)&wPB, (short)sizeof( wPB ) );
- */
- wPB.ioNamePtr = name;
- wPB.ioVRefNum = envRec.sysVRefNum;
- wPB.ioWDIndex = 0;
- wPB.ioWDProcID = '\0\0\0\0';
- wPB.ioWDVRefNum = 0;
-
- result = PBGetWDInfo( &wPB, false );
-
- if ( result ){
- return result;
- }
-
- *sysVolRefNumPtr = wPB.ioWDVRefNum;
- *blessedIDPtr = wPB.ioWDDirID;
-
- return noErr;
-
- }/* GetSysVolID */
-
- OSErr MakeFolder( long *idPtr, short volRefNum, long parentID, StringPtr name )
- {
- HParamBlockRec fPB;
- OSErr result;
-
- fPB.fileParam.ioCompletion = (IOCompletionUPP)NULL;
- fPB.fileParam.ioNamePtr = name;
- fPB.fileParam.ioVRefNum = volRefNum;
- fPB.fileParam.ioDirID = parentID;
-
- result = PBDirCreate( &fPB, false );
-
- if ( result ){
- return result;
- }
-
- *idPtr = fPB.fileParam.ioDirID; /* This is the dirID of the newly created folder */
-
- return noErr;
- }/* MakeFolder */
-
- /* The following is adapted from Richard Reich's "findDirectory" function */
-
- OSErr FindDirectory(short volNum, long parentDirID, StringPtr name, long *dirID)
- {
- CInfoPBRec pb;
- register OSErr err;
-
- /*
- ClearBlock( (char*)&pb, (short)sizeof( pb ) );
- */
-
- pb.dirInfo.ioFDirIndex = 0; /* Look up by name and parent vRefNum */
- pb.dirInfo.ioNamePtr = name;
- pb.dirInfo.ioVRefNum = volNum;
- pb.dirInfo.ioDrDirID = parentDirID;
- err = PBGetCatInfo(&pb, FALSE);
- if (err != noErr && err != fnfErr)
- return (err);
- if (err == fnfErr || (pb.dirInfo.ioFlAttrib & ioDirMask) == 0)
- return (dirNFErr);
- *dirID = pb.dirInfo.ioDrDirID;
- return (err);
- }/* FindDirectory */
-